﻿Imports CodeMatrix.Context
Imports System.Linq
Imports System.Data
Imports System.Data.SqlClient

Partial Class Apps_LogOut
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not HttpContext.Current.Session("session_id") Is Nothing Then
            ' Write log
            CodeMatrix.Business.GenericData.WriteLog(HttpContext.Current.Session("staff_no") & " ออกจากระบบ", 12, "O", HttpContext.Current.Session("staff_code"))
            ' Set the online status to offline
            CodeMatrix.Utilities.CodeHelper.ExecuteNonQuery("exec USP_UpdateOnlineStaff @staff_online_id, @staff_code, @session_id, @ip_address, @active", _
                                                            New SqlParameter("@staff_online_id", 0), _
                                                            New SqlParameter("@staff_code", HttpContext.Current.Session("staff_code")), _
                                                            New SqlParameter("@session_id", HttpContext.Current.Session("session_id")), _
                                                            New SqlParameter("@ip_address", HttpContext.Current.Request.UserHostAddress), _
                                                            New SqlParameter("@active", False))
        Else
            CodeMatrix.Business.GenericData.WriteLog("ออกจากระบบเนื่องจาก session timeout", 12, "O", -1)
        End If
        ' Abandon the session
        HttpContext.Current.Session.Abandon()
        ' Go to login page
        Response.Redirect("default.aspx")
    End Sub

End Class
